<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>css3buttonrenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_css3buttonrenderer.js.html">css3buttonrenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview An alternative imageless button renderer that uses CSS3 rather
<a name="line17"></a> * than voodoo to render custom buttons with rounded corners and dimensionality
<a name="line18"></a> * (via a subtle flat shadow on the bottom half of the button) without the use
<a name="line19"></a> * of images.
<a name="line20"></a> *
<a name="line21"></a> * Based on the Custom Buttons 3.1 visual specification, see
<a name="line22"></a> * http://go/custombuttons
<a name="line23"></a> *
<a name="line24"></a> * Tested and verified to work in Gecko 1.9.2+ and WebKit 528+.
<a name="line25"></a> *
<a name="line26"></a> * @author eae@google.com (Emil A Eklund)
<a name="line27"></a> * @author slightlyoff@google.com (Alex Russell)
<a name="line28"></a> * @see ../demos/css3button.html
<a name="line29"></a> */
<a name="line30"></a>
<a name="line31"></a>goog.provide(&#39;goog.ui.Css3ButtonRenderer&#39;);
<a name="line32"></a>
<a name="line33"></a>goog.require(&#39;goog.dom&#39;);
<a name="line34"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line35"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line36"></a>goog.require(&#39;goog.ui.Button&#39;);
<a name="line37"></a>goog.require(&#39;goog.ui.ButtonRenderer&#39;);
<a name="line38"></a>goog.require(&#39;goog.ui.ControlContent&#39;);
<a name="line39"></a>goog.require(&#39;goog.ui.INLINE_BLOCK_CLASSNAME&#39;);
<a name="line40"></a>goog.require(&#39;goog.ui.registry&#39;);
<a name="line41"></a>
<a name="line42"></a>
<a name="line43"></a>
<a name="line44"></a>/**
<a name="line45"></a> * Custom renderer for {@link goog.ui.Button}s. Css3 buttons can contain
<a name="line46"></a> * almost arbitrary HTML content, will flow like inline elements, but can be
<a name="line47"></a> * styled like block-level elements.
<a name="line48"></a> *
<a name="line49"></a> * @constructor
<a name="line50"></a> * @extends {goog.ui.ButtonRenderer}
<a name="line51"></a> */
<a name="line52"></a>goog.ui.Css3ButtonRenderer = function() {
<a name="line53"></a>  goog.ui.ButtonRenderer.call(this);
<a name="line54"></a>};
<a name="line55"></a>goog.inherits(goog.ui.Css3ButtonRenderer, goog.ui.ButtonRenderer);
<a name="line56"></a>
<a name="line57"></a>
<a name="line58"></a>/**
<a name="line59"></a> * The singleton instance of this renderer class.
<a name="line60"></a> * @type {goog.ui.Css3ButtonRenderer?}
<a name="line61"></a> * @private
<a name="line62"></a> */
<a name="line63"></a>goog.ui.Css3ButtonRenderer.instance_ = null;
<a name="line64"></a>goog.addSingletonGetter(goog.ui.Css3ButtonRenderer);
<a name="line65"></a>
<a name="line66"></a>
<a name="line67"></a>/**
<a name="line68"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line69"></a> * by this renderer.
<a name="line70"></a> * @type {string}
<a name="line71"></a> */
<a name="line72"></a>goog.ui.Css3ButtonRenderer.CSS_CLASS = goog.getCssName(&#39;goog-css3-button&#39;);
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/** @override */
<a name="line76"></a>goog.ui.Css3ButtonRenderer.prototype.getContentElement = function(element) {
<a name="line77"></a>  return /** @type {Element} */ (element);
<a name="line78"></a>};
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * Returns the button&#39;s contents wrapped in the following DOM structure:
<a name="line83"></a> *    &lt;div class=&quot;goog-inline-block goog-css3-button&quot;&gt;
<a name="line84"></a> *      Contents...
<a name="line85"></a> *    &lt;/div&gt;
<a name="line86"></a> * Overrides {@link goog.ui.ButtonRenderer#createDom}.
<a name="line87"></a> * @param {goog.ui.Control} control goog.ui.Button to render.
<a name="line88"></a> * @return {Element} Root element for the button.
<a name="line89"></a> * @override
<a name="line90"></a> */
<a name="line91"></a>goog.ui.Css3ButtonRenderer.prototype.createDom = function(control) {
<a name="line92"></a>  var button = /** @type {goog.ui.Button} */ (control);
<a name="line93"></a>  var classNames = this.getClassNames(button);
<a name="line94"></a>  var attr = {
<a name="line95"></a>    &#39;class&#39;: goog.ui.INLINE_BLOCK_CLASSNAME + &#39; &#39; + classNames.join(&#39; &#39;),
<a name="line96"></a>    &#39;title&#39;: button.getTooltip() || &#39;&#39;
<a name="line97"></a>  };
<a name="line98"></a>  return button.getDomHelper().createDom(&#39;div&#39;, attr, button.getContent());
<a name="line99"></a>};
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * Returns true if this renderer can decorate the element.  Overrides
<a name="line104"></a> * {@link goog.ui.ButtonRenderer#canDecorate} by returning true if the
<a name="line105"></a> * element is a DIV, false otherwise.
<a name="line106"></a> * @param {Element} element Element to decorate.
<a name="line107"></a> * @return {boolean} Whether the renderer can decorate the element.
<a name="line108"></a> * @override
<a name="line109"></a> */
<a name="line110"></a>goog.ui.Css3ButtonRenderer.prototype.canDecorate = function(element) {
<a name="line111"></a>  return element.tagName == goog.dom.TagName.DIV;
<a name="line112"></a>};
<a name="line113"></a>
<a name="line114"></a>
<a name="line115"></a>/** @override */
<a name="line116"></a>goog.ui.Css3ButtonRenderer.prototype.decorate = function(button, element) {
<a name="line117"></a>  goog.dom.classes.add(element, goog.ui.INLINE_BLOCK_CLASSNAME,
<a name="line118"></a>      this.getCssClass());
<a name="line119"></a>  return goog.ui.Css3ButtonRenderer.superClass_.decorate.call(this, button,
<a name="line120"></a>      element);
<a name="line121"></a>};
<a name="line122"></a>
<a name="line123"></a>
<a name="line124"></a>/**
<a name="line125"></a> * Returns the CSS class to be applied to the root element of components
<a name="line126"></a> * rendered using this renderer.
<a name="line127"></a> * @return {string} Renderer-specific CSS class.
<a name="line128"></a> * @override
<a name="line129"></a> */
<a name="line130"></a>goog.ui.Css3ButtonRenderer.prototype.getCssClass = function() {
<a name="line131"></a>  return goog.ui.Css3ButtonRenderer.CSS_CLASS;
<a name="line132"></a>};
<a name="line133"></a>
<a name="line134"></a>
<a name="line135"></a>// Register a decorator factory function for goog.ui.Css3ButtonRenderer.
<a name="line136"></a>goog.ui.registry.setDecoratorByClassName(
<a name="line137"></a>    goog.ui.Css3ButtonRenderer.CSS_CLASS,
<a name="line138"></a>    function() {
<a name="line139"></a>      return new goog.ui.Button(null,
<a name="line140"></a>          goog.ui.Css3ButtonRenderer.getInstance());
<a name="line141"></a>    });
<a name="line142"></a>
<a name="line143"></a>
<a name="line144"></a>// Register a decorator factory function for toggle buttons using the
<a name="line145"></a>// goog.ui.Css3ButtonRenderer.
<a name="line146"></a>goog.ui.registry.setDecoratorByClassName(
<a name="line147"></a>    goog.getCssName(&#39;goog-css3-toggle-button&#39;),
<a name="line148"></a>    function() {
<a name="line149"></a>      var button = new goog.ui.Button(null,
<a name="line150"></a>          goog.ui.Css3ButtonRenderer.getInstance());
<a name="line151"></a>      button.setSupportedState(goog.ui.Component.State.CHECKED, true);
<a name="line152"></a>      return button;
<a name="line153"></a>    });
</pre>


</body>
</html>
